﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;
using InstantNaukriDAL;

public partial class Admin : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string roleid = "";
            clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
            if (Request.QueryString["roleid"] != null && Request.QueryString["roleid"] != "")
            {
                roleid = clsEncryptionDecryption.Decrypt(Request.QueryString["roleid"].ToString());
                Session["RoleId"] = Request.QueryString["roleid"].ToString();
            }
            else
            {
                if (Session["roleid"] != null)
                    roleid = clsEncryptionDecryption.Decrypt(Session["roleid"].ToString());
            }
            IN_TB_USER objIN_TB_USER = new IN_TB_USER();
            if (Session["UserId"] != null)
                objIN_TB_USER = objclsUserLoginDAL.GetUserByID(Convert.ToInt32(Session["UserId"].ToString()));
            if (objIN_TB_USER != null && roleid != "")
            {
                clsPageDAL objclsPageMstDAL = new clsPageDAL();
                List<IN_TB_PAGE_MST> objIN_TB_PAGE_MST = new List<IN_TB_PAGE_MST>();
                objIN_TB_PAGE_MST = objclsPageMstDAL.GetPageByRoleId(Convert.ToInt32(roleid));
                rptMenu.DataSource = objIN_TB_PAGE_MST;
                rptMenu.DataBind();
            }
            else
            {
                clsPageDAL objclsPageMstDAL = new clsPageDAL();
                List<IN_TB_PAGE_MST> objIN_TB_PAGE_MST = new List<IN_TB_PAGE_MST>();
                objIN_TB_PAGE_MST = objclsPageMstDAL.GetPageByRoleId(0);
                rptMenu.DataSource = objIN_TB_PAGE_MST;
                rptMenu.DataBind();
            }
        }
    }


    protected void rptMenu_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        //if (e.Item.ItemIndex >= 0)
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HyperLink ALink = (HyperLink)e.Item.FindControl("aLinks");
            HiddenField hfUrl = (HiddenField)e.Item.FindControl("hfPAGEURL");
            if (Session["RoleId"] != null)
            {
                if (Convert.ToString(Session["RoleId"]) != "0")
                    ALink.NavigateUrl = hfUrl.Value.ToString() + "?roleid=" + Convert.ToString(Session["RoleId"]);
                else
                    ALink.NavigateUrl = hfUrl.Value.ToString();
            }
        }
    }
    protected void btnLogout_Click(object sender, ImageClickEventArgs e)
    {
        Session["RoleId"] = null;
        Session["UserId"] = null;
        Session["EmployerId"] = null;
        Response.Redirect("Default.aspx");
    }
}
